#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<unordered_map>
#include<vector>
using namespace std;

class Solution {
public:
    unordered_map<char, string> phoneMap{
                {'2', "abc"},
                {'3', "def"},
                {'4', "ghi"},
                {'5', "jkl"},
                {'6', "mno"},
                {'7', "pqrs"},
                {'8', "tuv"},
                {'9', "wxyz"}
    };
    string path;
    vector<string> ret;
    void dfs(string digits, size_t pos)
    {
        if (pos == digits.size())
        {
            ret.push_back(path);
            return;
        }
        for (auto ch : phoneMap[digits[pos]])
        {
            path += ch;
            dfs(digits, pos + 1);
            path.pop_back();
        }
    }
    vector<string> letterCombinations(string digits) {
        if (digits.size() == 0) return {};
        dfs(digits, 0);
        return ret;
    }

    string convert(string s, int numRows) {
        if (numRows == 1) return s;
        int d = 2 * numRows - 2, n = s.length();
        string ret;
        for (int i = 0; i < n; i += d)
            ret += s[i];
        for (int k = 1; k < numRows - 1; ++k)
        {
            for (int i = k, j = d - k; i < n || j < n; i += d, j += d)
            {
                if (i < n) ret += s[i];
                if (j < n) ret += s[j];
            }
        }
        for (int i = numRows - 1; i < n; i += d)
            ret += s[i];
        return ret;
    }

    bool checkPossibility(vector<int>& nums) {
        int n = nums.size(), cnt = 0;
        for (int i = 0; i < n - 1; ++i)
        {
            if (nums[i + 1] < nums[i])
            {
                ++cnt;
                if (cnt > 1) return false;
                if (i > 0 && nums[i + 1] < nums[i - 1]) nums[i + 1] = nums[i];
            }
        }
        return true;

};